// components/upimg/upimg.ts
const app = getApp()  // 获取App实例
Component({
  options: {
    multipleSlots: true // 启用多插槽支持
  },

  properties: {
    imglist: {
      type: Array,
      value: [], // 设置默认值
      observer(newVal, oldVal) {
        console.log('title 变化:', oldVal, '→', newVal);
        this.setData({ keylist: newVal });
      }
    }
  },
  // observers: {
  //   'imglist': function (newCount) {
  //     console.log('count 变化:', newCount);
  //   }
  // },
  /**
   * 页面的初始数据
   */
  data: {
    up: app.getImgUrl('up.png'),
    keylist: [],
  },
  methods: {
    delthis(e) {
      const index = e.currentTarget.dataset.index;
      let keylist = this.data.keylist
      keylist.splice(index, 1)
      this.setData({
        keylist: keylist
      })
      this.triggerEvent('giveup', {
        returnval: this.data.keylist
      });
    },
    async chackimg() {
      // 9 表示最多可以一次性选择多少张
      let returnval = await app.globalData.upimgJs.chackimg(9)
      console.log(
        returnval
      )


      this.setData({
        keylist: returnval.imgkeylist,
      });
      this.triggerEvent('giveup', {
        returnval: this.data.keylist
      });
    },
  },
  onShow() {
    this.chackimg()
  },
})